package com.tfjybj.itoo.exam.provider.service.impl;
import com.dmsdbj.itoo.tool.base.service.impl.BaseServicePlusImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tfjybj.itoo.exam.entity.CourseScheduleEntity;
import com.tfjybj.itoo.exam.entity.SemesterEntity;
import com.tfjybj.itoo.exam.model.CourseScheduleModel;
import com.tfjybj.itoo.exam.provider.dao.CourseScheduleDao;
import com.tfjybj.itoo.exam.provider.service.CourseScheduleService;
import com.tfjybj.itoo.exam.provider.service.SemesterService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * CourseScheduleService接口实现类
 * ${base}表
 *
 * @author 杨江涛
 * @version 2.0.0
 * @since 2.0.0 2018-11-15 10:35:56
 */
@Service("courseScheduleService")
public class CourseScheduleServiceImpl extends BaseServicePlusImpl<CourseScheduleDao, CourseScheduleEntity> implements CourseScheduleService {
	
	//region 模板生成

    @Resource
    private CourseScheduleDao courseScheduleDao;
    @Resource
    private SemesterService semesterService;

	 @Override
    public PageInfo<CourseScheduleEntity> queryByLikeClassId(String classId, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        return new PageInfo<>(courseScheduleDao.queryLikeClassId(classId));
    }

    //endregion

    /* **********************************以下为非模板生成的内容********************************* */

    /**
     *   查看该考场下的所有监考老师
     * @author      王雪芬
     * @return  CourseScheduleEntity
     * @param invigilatorMainId String
     * @since 2.0.0  2018-11-19 12:01:36
     */
    @Override
    public CourseScheduleEntity findByTeacher(String invigilatorMainId) {
        if(StringUtils.isEmpty(invigilatorMainId)){
            return null;
        }
      return  courseScheduleDao.findByTeacher(invigilatorMainId);
    }
    @Override
    public List<CourseScheduleModel> querycourseName(List<String> newList) {
        return courseScheduleDao.querycourseName(newList);
    }

    /**
     *   根据课程id返回课程名称
     * @author      杨江涛
     * @return  CourseScheduleEntity
     * @param   courseId 课程id
     * @since 2.0.0  2018-11-19 12:01:36
     */
    @Override
    public String findByCourseId(String courseId) {
        CourseScheduleEntity courseScheduleEntity = courseScheduleDao.findByCourseId(courseId);
        if (courseScheduleEntity==null){
            return "";
        }else {
            return courseScheduleEntity.getCourseName();
        }

    }

    /**
     *   无参查询课程信息
     *
     * @author      杨江涛
     * @return  courseScheduleList
     * @since 2.0.0  2018-11-24 12:01:31
     */
    @Override
    public List<CourseScheduleEntity> findCourse() {
        List<SemesterEntity> semesterEntityList=(List<SemesterEntity>)semesterService.selSemesterId().getData();
        String semesterId="";
        if(CollectionUtils.isEmpty(semesterEntityList)){
            semesterId=semesterEntityList.get(0).getCode();
        }
         return courseScheduleDao.findCourse(semesterId);
    }

}
